package algorithm.arithmetic.分解质因数;

/**
 * 例输入
 * 90
 *
 * 输出
 * 2*3*3*5
 * @author xinchen by 2016/11/28
 * @version 1.0
 */
public class Solution {
    // 将一个正整数分解质因数
    public static void main(String[] args) {
        int nowPrime = 2;
        int num = Integer.parseInt(args[0]);
        int sqrt = (int) Math.sqrt(num);
        StringBuilder stringBuilder = new StringBuilder();
        while (nowPrime <= num) {
            if (nowPrime > sqrt) {
                stringBuilder.append('*').append(num);
                num = 1;
            } else if (num % nowPrime == 0) {
                stringBuilder.append('*').append(nowPrime);
                num = num / nowPrime;
            } else {
                nowPrime = getNextPrime(nowPrime);
            }
        }
        System.out.println(stringBuilder.substring(1));
    }

    private static int getNextPrime(int min) {
        for (int i = min + 1; ; i++) {
            if (isPrime(i)) {
                return i;
            }
        }
    }

    private static boolean isPrime(int num) {
        int max = (int) Math.sqrt(num);
        for (int i = 2; i <= max; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
